package cool.webstudy.admin.constant.enums.rescode;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 莫振双
 * @date 2025/1/4 15:52
 * @description: 配置相关返回码枚举
 */
@Slf4j
public enum ConfigResCodeEnum implements BaseResCodeEnum {
    RC_ERROR_CREATE("100001","配置创建失败！"),
    RC_ERROR_DELETE("100002","配置删除失败！"),
    RC_ERROR_UPDATE("100003","配置更新失败！"),
    RC_CONFIG_NOT_EXIST("100004","{0}不存在！"),
    RC_ERROR_QUERY("100005","配置查询失败！"),
    RC_ERROR_ASYNC_CONFIG_TO_DB("100006","同步配置至数据库失败！失败详情：{0}"),
    RC_ERROR_QUERY_PARAM_MISS("100007","配置查询参数缺失！"),
    ;
    private String code;
    private String msg;
    ConfigResCodeEnum(String code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String msg() {
        return msg;
    }
    /**
     * 根据code获取msg静态方法，每个响应状态码枚举类都应有这个方法
     */
    public static ConfigResCodeEnum getMsgByCode(String code) {
        for (ConfigResCodeEnum configResCodeEnum : ConfigResCodeEnum.values()) {
            if (configResCodeEnum.code().equals(code)) {
                return configResCodeEnum;
            }
        }
        log.error("getMsgByCode error:无法获取枚举值");
        return null;
    }
}
